package com.centronix.web;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import com.centronix.domain.ProductCatagory;
import com.centronix.manager.ProductCatManager;
import com.centronix.util.WebUtil;

@ManagedBean(name = "productCatBean")
@SessionScoped
public class ProductCatBean implements Serializable{

	private static final long serialVersionUID = 1L;

	@ManagedProperty("#{productCatManager}")
    private ProductCatManager productCatManager;
	
	private ProductCatagory newProductCatagory = new ProductCatagory();
	private ProductCatagory selectedProductCatagory = new ProductCatagory();
	
	private List<ProductCatagory> allProductCatagory = new ArrayList<ProductCatagory>(0);
	
	private boolean dataVisible = false;

	public String findAllProductCatagory(){
		allProductCatagory = productCatManager.findAllProdCat();
		dataVisible = true;
		return "productcat";
	}
	
	public String saveNewProductCatagory(){
		productCatManager.saveProdCat(newProductCatagory);
		allProductCatagory = productCatManager.findAllProdCat();
		newProductCatagory = new ProductCatagory();
		WebUtil.showSuccessfulMessage("Record Saved!");
		return "";
	}
	
	public String updateProductCatagory(){
		productCatManager.saveProdCat(selectedProductCatagory);
		allProductCatagory = productCatManager.findAllProdCat();
		selectedProductCatagory = new ProductCatagory();
		WebUtil.showSuccessfulMessage("Record Updated!");
		return "";
	}
	
	public String deleteProductCatagory(){
		productCatManager.deleteProdCat(selectedProductCatagory.getCatagoryId());
		allProductCatagory = productCatManager.findAllProdCat();
		selectedProductCatagory = new ProductCatagory();
		WebUtil.showSuccessfulMessage("Record Deleted!");
		return "";
	}

	public ProductCatManager getProductCatManager() {
		return productCatManager;
	}

	public void setProductCatManager(ProductCatManager productCatManager) {
		this.productCatManager = productCatManager;
	}

	public ProductCatagory getNewProductCatagory() {
		return newProductCatagory;
	}

	public void setNewProductCatagory(ProductCatagory newProductCatagory) {
		this.newProductCatagory = newProductCatagory;
	}

	public ProductCatagory getSelectedProductCatagory() {
		return selectedProductCatagory;
	}

	public void setSelectedProductCatagory(ProductCatagory selectedProductCatagory) {
		this.selectedProductCatagory = selectedProductCatagory;
	}

	public List<ProductCatagory> getAllProductCatagory() {
		return allProductCatagory;
	}

	public void setAllProductCatagory(List<ProductCatagory> allProductCatagory) {
		this.allProductCatagory = allProductCatagory;
	}

	public boolean isDataVisible() {
		return dataVisible;
	}

	public void setDataVisible(boolean dataVisible) {
		this.dataVisible = dataVisible;
	}
	

}
